getAjaxReq("statistics/totalRechargeApplyByType", {}, function (res) {
    var sector = echarts.init(document.getElementById('sector0'));
    $("#sector1").css({"width": '100%', "height": '300px'});
    var sector1 = echarts.init(document.getElementById('sector1'));
    $("#sector1").hide();
    var option = {
        title: {text: "交易笔数统计", x: "left",textStyle:{
            fontStyle:'normal',
            fontSize:14
        }},
        tooltip: {trigger: 'item'},
        legend: {orient: 'vertical', x: 'right'}
    }
    var option1 = {
        title: {text: "交易金额统计", x: "left",textStyle:{
            fontStyle:'normal',
            fontSize:14
        }},
        tooltip: {trigger: 'item'},
        legend: {orient: 'vertical', x: 'right'}
    }
    if (res.code == 1) {
        var list1 = new Array();
        var list2 = new Array();
        res.data.forEach(function (e) {
            if (e.type == 1) {
                list1.push({name: "后台支付", value: e.count})
                list2.push({name: "后台支付", value: e.amount})
            } else if (e.type == 2) {
                list1.push({name: "微信支付", value: e.count})
                list2.push({name: "微信支付", value: e.amount})
            } else if (e.type == 4) {
                list1.push({name: "支付宝支付", value: e.count})
                list2.push({name: "支付宝支付", value: e.amount})
            }
        })
        option.series = [
            {
                name: '交易笔数',
                type: 'pie',
                radius: '70%',
                center: ['50%', '50%'],
                color:['#ff9e00','#00d00b','#56abe4'],
                data: list1
            }
        ]
        option1.series = [
            {
                name: '交易金额',
                type: 'pie',
                radius: '70%',
                color:['#ff9e00','#00d00b','#56abe4'],
                center: ['50%', '50%'],
                data: list2
            }
        ]
    }
    else {
        option.series = []
        option1.series = []
    }
    sector.setOption(option)
    sector1.setOption(option1)
})

getAjaxReq("statistics/warnAmmeters", {warnTime: 60 * 24}, function (res) {
    var option = {
        tooltip: {
            trigger: 'item',
            formatter: "{a} <br/>{b} : {c} ({d}%)"
        },
        legend: {
            orient: 'vertical',
            x: 'right',
            data: ['在线数', '离线数']
        }
    };
    var warnAmmeters = echarts.init(document.getElementById("warnAmmeters"));
    if (res.code == 1) {
        var total = res.data.total
        var warnTotal = res.data["warnTotal"]
        option.series = [
            {
                name: "电表在线率",
                type: 'pie',
                radius: ['70%', '60%'],
                center: ['50%', '50%'],
                color: ['#cb2a08', '#13ad6b'],
                data: [
                    {
                        value: warnTotal,
                        name: '离线数',
                        label: {show: false},
                        labelLine: {show: false}
                    },
                    {
                        value: total - warnTotal, name: '在线数',
                        label: {
                            show: true,
                            position: 'center',
                            formatter: function (params) {
                                if (total != 0){
                                    return (params.value / total * 100).toFixed(2) + '%'
                                } else
                                    return '0%'

                            },
                            color: '#13ad6b',
                            fontSize: 24
                        }
                    }
                ]
            }
        ]
    } else {
        option.series = []
    }
    warnAmmeters.setOption(option)
})
